#!/usr/bin/perl

use strict;

for(1..1){
  create_fork($_);
}

sub create_fork{
    my $num = shift;
#    my $pid = fork() || warn "cannot create fork";
    my $pid = fork();
    my $string = "number:$num\n";
    
#    my $parent_pid;
#    if( waitpid($pid,0) != -1 ){
#        print "pid:$pid : start parent\n";
#    }
    
    if ($pid) {
        print "\nparent: self:$$ pid:$pid parent\n";
#        sleep(5);
#        print "2: self:$$ pid:$pid parent\n";
        print "parent:$string\n";
#        exit();
    }
    else{
        print "\nchild: self:$$ pid:$pid child\n";
        print "child:$string \n";
#        sleep(1);
#        exit();
    }
}

#my $i = waitpid($pid, 0);

#print "i : $i \n";

#if( waitpid($pid, 0) ){
#    print "ssss\n";
#}

__END__
pipe $r,$w;

print $r 'aabbcc';

while($l = $w){
    print $l."\n";
}

